package com.heima.article.esTest;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.article.entity.ApArticle;
import com.heima.article.es.ApArticleSearch;
import com.heima.article.es.ArticleRepository;
import com.heima.article.service.IApArticleService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author : wuqiang
 * @date : 2022年10月23日
 */
@SpringBootTest
public class ElasticSearchTesst {
    @Autowired
    private IApArticleService apArticleService;
    @Autowired
    private ArticleRepository articleRepository;

    @Test
    void testAdd() {
        LambdaQueryWrapper<ApArticle> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ApArticle::getIsDown, false);
        queryWrapper.eq(ApArticle::getIsDelete, false);
        List<ApArticle> list = apArticleService.list(queryWrapper);

        List<ApArticleSearch> articleSearchList = list.stream().map(apArticle -> {
            ApArticleSearch apArticleSearch = new ApArticleSearch();
            BeanUtils.copyProperties(apArticle, apArticleSearch);
            return apArticleSearch;
        }).collect(Collectors.toList());

        articleRepository.saveAll(articleSearchList);

    }
}
